import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;


public class Main_ControlPanel extends Frame 
{
 
  Button demo1Button = new Button("Demo 1");
  Button demo2Button = new Button("Demo 2");
  Button demo3Button = new Button("Demo 3");
  Button exitButton = new Button("Exit");

    
 //switch to swing   
/* 
  JButton demo1Button = new JButton("Demo 1");
  JButton demo2Button = new JButton("Demo 2");
  JButton demo3Button = new JButton("Demo3");
  JButton exitButton = new JButton("Close window");
*/  
    
  String[] args = null;

  public Main_ControlPanel() 
  {
    super();
  }

  public Main_ControlPanel( String title ) 
  {
    super(title);
  }

  public void init( Kernel useKernel , String[] argsIn ) 
  {
    setLayout( null );
    setBackground( Color.white );
    setForeground( Color.black );
    resize( 1024 , 768 );
    setFont( new Font( "Courier", 0, 18 ) );   
    
    
//   demo1Button.setForeground( Color.blue );
//    demo1Button.setBackground( Color.lightGray );
    demo1Button.reshape( 400,350,80,40 );
    add( demo1Button );    

//    demo2Button.setForeground( Color.blue );
//    demo2Button.setBackground( Color.lightGray );
    demo2Button.reshape( 400,400,80,40 );
    add( demo2Button );

//    demo3Button.setForeground( Color.blue );
//    demo3Button.setBackground( Color.lightGray );
    demo3Button.reshape( 400,450,80,40 );
    add( demo3Button );

//    exitButton.setForeground( Color.blue );
//    exitButton.setBackground( Color.lightGray );
    exitButton.reshape( 400,500,80,40 );
    add( exitButton );
 
    args = argsIn;
 
    show();
  }

  public void paintPage( Page page ) 
  {

  }

  public void setStatus(String status) {
  }

  public void addPhysicalPage( int pageNum , int physicalPage ) 
  {

  }

  public void removePhysicalPage( int physicalPage ) 
  {

  }


  public boolean action( Event e, Object arg )
  {
   
    //run demo1 - sample MMU  
    if ( e.target == demo1Button ) 
    {
      setStatus( "Demo1" );
      demo1Button.disable();

      ControlPanel controlPanel;
      Kernel kernel;
      kernel = new Kernel();
      controlPanel = new ControlPanel( "Memory Management" );
      if ( args.length == 1 ) 
      {
        controlPanel.init( kernel , args[0] , null );
      }
      else
      {
        controlPanel.init( kernel , args[0] , args[1] );
      }
                        
      demo1Button.enable();
      return true;
    } 
    else if ( e.target == demo2Button )
    {

      return true;
    }
    else if ( e.target == demo3Button )
    {

      return true;
    }
    else if ( e.target == exitButton )
    {
      System.exit(0);
      return true;
    }

    return true;
  }  
 
  //switch to swing
 /* 
  public boolean actionPerformed( ActionEvent e, Object arg )
  {
          
      //System.exit(0);
    //run demo1 - sample MMU  
      if (!(e.getSource() instanceof JButton)) return true;
      JButton b = (JButton) e.getSource();
      String buttonName = b.getName();
      if (buttonName == null) return true;
    if( buttonName.equals("Demo 1")) 
    {
      setStatus( "Demo1" );
      demo1Button.disable();

      ControlPanel controlPanel;
      Kernel kernel;
      kernel = new Kernel();
      controlPanel = new ControlPanel( "Memory Management" );
      if ( args.length == 1 ) 
      {
        controlPanel.init( kernel , args[0] , null );
      }
      else
      {
        controlPanel.init( kernel , args[0] , args[1] );
      }
                        
      demo1Button.enable();
      return true;
    } 
    else if ( e.equals(demo2Button) )
    {

      return true;
    }
    else if ( e.equals(demo3Button) )
    {

      return true;
    }
    else if ( e.equals(exitButton) )
    {
      System.exit(0);
      return true;
    }
    return true;
  }
*/
  
}
